/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Login.java
 *
 * Created on 21/06/2012, 08:06:03 AM
 */

package view;

import VO.UserVO;
import facade.UserFacade;

/**
 *
 * @author Estudiante
 */
public class Login extends javax.swing.JFrame {
    
    UserFacade userFacade;
    UserVO userVO;
    

    /** Creates new form Login */
    public Login() {
        userFacade = new UserFacade();
        userVO = new UserVO();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        Texname = new javax.swing.JTextField();
        textpass = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        bIngre = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre");

        jLabel2.setText("Contraseña");

        jLabel4.setText("Ingresar");

        bIngre.setText("Ingresar");
        bIngre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bIngreMouseClicked(evt);
            }
        });
        bIngre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bIngreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3)
                        .addComponent(jLabel1)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bIngre)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Texname)
                            .addComponent(textpass, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(83, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(Texname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(textpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bIngre))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bIngreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bIngreActionPerformed
        // TODO add your handling code here:
        String name;
        String password;
        String rol;
        name= this.Texname.getText();
        password= this.textpass.getText();
        userVO = userFacade.loginUser(name,password);
        
        
        if(userVO!=null){
            rol=userVO.getRol();
            if(name.matches(userVO.getLogin()) && 
                        password.matches(userVO.getPassword())){
                if(rol.equals("analista1")){
                    setVisible(false);
                    Analista1 analista1 = new Analista1();
                    analista1.setVisible(true);
                }else if(rol.equals("analista2")){
                    setVisible(false);
                    Analista2 analista2 = new Analista2();
                    analista2.setVisible(true);
                }else if(rol.equals("tecnico")){
                    setVisible(false);
                    Tecnico tecnico = new Tecnico();
                    tecnico.setVisible(true);
                }
                        
                }
        }
    }//GEN-LAST:event_bIngreActionPerformed

    private void bIngreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bIngreMouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_bIngreMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Texname;
    private javax.swing.JButton bIngre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField textpass;
    // End of variables declaration//GEN-END:variables

}
